/*
 * Copyright (c) 2014 laidian. All Rights Reserved.
 * @author yaoyuming
 * @date  2020-04-14 17:15
 */
package com.yao.fin.mapper.sql;


import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.yao.common.enums.business.fin.LabelEnum;
import com.yao.fin.entity.FinancialTemplateEntity;
import com.yao.fin.entity.dto.FinancialTemplateDto;

/**
 * 快学sql组装
 * @author yaoyuming
 * @date 2020/04/14 17:15
 */
public class FinancialTemplateWrapper {

    /**
      * 功能描述 : 导出报表的查询条件
      * @param dto
      * @author yaoyuming
      * @date 2020/4/14
      * @return {@link Wrapper< FinancialTemplateDto>}
      */
    public static Wrapper<FinancialTemplateDto> withPage(FinancialTemplateDto dto){
        LambdaQueryWrapper<FinancialTemplateDto> query =  Wrappers.lambdaQuery();
        if(ObjectUtil.isNull(dto)){
            dto = new FinancialTemplateDto();
        }

        if (null != dto.getLabelQo()) {
            dto.setLabel(LabelEnum.getEnumByCode(dto.getLabelQo()));
        }

        FinancialTemplateDto financialTemplateDto = dto.buildParams();

        query.eq(null != dto.getLabel(), FinancialTemplateDto::getLabel, financialTemplateDto.getLabel())
                .ge(null != financialTemplateDto.getBeginDate(), FinancialTemplateEntity::getTrainDate, financialTemplateDto.getBeginDate())
                .le(null != financialTemplateDto.getEndDate(), FinancialTemplateEntity::getTrainDate, financialTemplateDto.getEndDate())
                .orderByAsc(FinancialTemplateEntity::getTrainDate);

        return query;
    }
}